#include<iostream>
#include<vector>
using namespace std;
#include"RBtree.h"
#include"AVLtree.h"
#include<time.h>
#include<stdlib.h>

void TestRBtree()
{
	RBtree<int, int> t;
	//vector<int> v = { 16, 3, 7, 11, 9, 26, 18, 14, 15 };
	vector<int> v = { 4, 2, 6, 1, 3, 5, 15, 7, 16, 14 };
	for (auto& e : v)
	{
		t.Insert(make_pair(e, e));
	}
	t.InOrder();
	cout << t.IsValidRBTree() << endl;
}


void test_time()
{
	vector<int> v;
	RBtree<int, int> rbtree;
	AVLtree<int, int> avltree;

	size_t n = 10000000;
	v.reserve(10000000);
	srand(time(0));
	for (size_t i = 0; i < n; i++)
	{
		v.push_back(rand());
	}

	
	size_t begin1 = clock();
	for (auto& x : v)
	{
		avltree.Insert(make_pair(x, x));
	}
	size_t end1 = clock();

	size_t begin2 = clock();
	for (auto& x : v)
	{
		rbtree.Insert(make_pair(x, x));
	}
	size_t end2 = clock();

	cout << end1 - begin1 << endl;
	cout << end2 - begin2 << endl;
}

int main()
{
	//TestRBtree();
	test_time();
	return 0;
}